/**
 * @file TcpServer.cc
 * @author zziywang (zziywang@163.com)
 * @brief { life is too short to learn cpp! }
 * @version 1.0
 * @date 2022-05-08
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "TcpServer.hh"

namespace snow
{
TcpServer::TcpServer(const string &ip, unsigned short port)
    : acceptor_(ip, port), eventLoop_(acceptor_) {}

TcpServer::TcpServer(unsigned short port)
    : acceptor_(port), eventLoop_(acceptor_) {}

TcpServer::TcpServer(const sockaddr_in addr)
    : acceptor_(addr), eventLoop_(acceptor_) {}

void TcpServer::start()
{
    acceptor_.ready();
    printf("Acceptor is ready!\n");

    eventLoop_.loop(); // 开始事件循环
}

void TcpServer::setConnectionCallBack(const TcpConnectionCallBack &cb)
{
    eventLoop_.setConnectionCallBack(std::move(cb));
}
void TcpServer::setMessageCallBack(const TcpConnectionCallBack &cb)
{
    eventLoop_.setMessageCallBack(std::move(cb));
}
void TcpServer::setCloseCallBack(const TcpConnectionCallBack &cb)
{
    eventLoop_.setCloseCallBack(std::move(cb));
}

} // namespace snow